import wsgiref.handlers
from google.appengine.ext import webapp

from google.appengine.ext.webapp import template

import logging
from urlparse import urlparse
import os
		
class flashbsm(webapp.RequestHandler):

	def get(self):
	
		swf = 'http://' + urlparse(self.request.url).netloc + '/swfs/settings.swf';
		
		template_values = {
			'type': 'Flex',
			'title': 'flashbsm',
			'description': '',
			'swf': swf,
			'width': '100%',
			'height': '100%'			
		}

		path = os.path.join(os.path.dirname(__file__), 'templates/flashbsm.html')
		self.response.out.write(template.render(path, template_values, debug=True))
		
class NotFoundHandler(webapp.RequestHandler):
	
	def get(self):
		# Not found
		template_vars = {
		'title': 'Error 404 Kitten: I\'m sorry, I tried really hard to find it.',
		'content': '<img src="/images/404kitten.jpg" width="375" height="500" alt="404 Kitten."/><p><a href="http://flickr.com/photos/mydnight296/2343975616/">Photo</a> by <a href="http://flickr.com/people/mydnight296/">Vannessa</a>.</p>'
		}
		path = os.path.join(os.path.dirname(__file__), 'templates/simple.html')
		self.response.out.write(template.render(path, template_vars, debug=True))
	
def main():
	application = webapp.WSGIApplication([
		('/', flashbsm),
		('/.*', NotFoundHandler)
	], debug=True)
	wsgiref.handlers.CGIHandler().run(application)
  
if __name__ == '__main__':
  main()
